home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / exeutil.zip / NEWLOAD.ASM < prev    next >
Assembly Source File  |  1987-11-04  |  2KB  |  78 lines

  1. ;new loader for packed EXE files
  2. ;must be converted to a typed constant for insertion to MM
  3.  
  4. CODE    SEGMENT PARA PUBLIC
  5.  
  6.         ORG   0                ;will be a unique segment as loader
  7.  
  8.         ASSUME  CS:CODE,DS:nothing
  9.  
  10.         PUBLIC  NewLoader, LoadTable, OrigIp
  11.  
  12. ;****************************************************** NewLoader
  13.  
  14. ;procedure NewLoader
  15. ;  Loader for packed EXE files
  16. ;  Note: do not use stack before relocating
  17.  
  18. NewSegFlag   EQU  0FFFFh
  19.  
  20. NewLoader    PROC FAR
  21.  
  22.         JMP SHORT  Relocate    ;two bytes
  23.  
  24. OrigIp  DW     0               ;patched in by PACK
  25. OrigCs  DW     0               ;patched in by PACK
  26. ProgDS  DW     0               ;location to save program's initial DS
  27. ProgES  DW     0               ;location to save program's initial DS
  28.  
  29. Relocate:
  30.         MOV    ProgDS,DS       ;save DS
  31.         MOV    ProgES,ES       ;save ES
  32.         MOV    BX,ES           ;store base program address in BX
  33.         ADD    BX,0010H        ;offset for PSP
  34.  
  35.         MOV    AX,CS
  36.         MOV    DS,AX           ;point DS:SI to LoadTable
  37.         MOV    SI,offset LoadTable
  38.         CLD                    ;go forward
  39.  
  40. NewLoad:
  41.         LODSW                  ;next word from load table
  42.         CMP    AX,NewSegFlag   ;start of new segment following?
  43.         JNZ    DoFixup         ;no, do the fixup
  44.  
  45.         LODSW                  ;get new segment
  46.         CMP    AX,NewSegFlag   ;flag for end of table?
  47.         JZ     Done            ;yes, we're done
  48.  
  49.         ADD    AX,BX           ;add base segment to one in load table
  50.         MOV    ES,AX           ;save new segment in ES
  51.         LODSW                  ;get fixup offset
  52.  
  53. DoFixup:
  54.         MOV    DI,AX           ;fixup offset into index register
  55.         ADD    ES:[DI],BX      ;add program base address to fixup word
  56.  
  57.         JMP    NewLoad         ;do it again
  58.  
  59. Done:
  60.         MOV    ES,ProgES       ;get original ES and DS back
  61.         MOV    DS,ProgDS
  62.  
  63.         MOV    AX,BX
  64.         ADD    AX,OrigCs       ;relocate origcs
  65.         PUSH   AX              ;return segment on stack
  66.         MOV    AX,OrigIP       ;get origip
  67.         PUSH   AX              ;return address on stack
  68.         RET                    ;return to original startup code
  69.  
  70.         even                   ;keep LoadTable on word boundary for speed
  71. LoadTable  LABEL BYTE          ;start of LoadTable
  72.  
  73. NewLoader      ENDP
  74.  
  75. CODE    ENDS
  76.  
  77.         END
  78.